package com.ruge._08_springboot_springdata_jpa.controller._03_mapping._05_component;

import com.ruge._08_springboot_springdata_jpa.Application;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;

import javax.persistence.EntityManager;
import java.util.List;

/**
 * 创建人 ：爱丽丝、如歌
 * 创建时间 ：2019-07-05  22:43
 * 描述 ：组件测试
 */
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = Application.class)//这里是启动类
public class TestComponent {
    @Autowired
    private EntityManager entityManager;
    @Test
    @Transactional
    public void testSave() {
        ComponentCompany componentCompany = new ComponentCompany("公司一号",new ComponentAddress("吉林市","长春市","南关区"),new ComponentAddress("吉林市","长春市","农安县"));
        entityManager.persist(componentCompany);
        entityManager.flush();
    }

    @Test
    @Transactional
    public void testSelect() {
       List list = entityManager.createQuery("select  t from ComponentCompany t").getResultList();
       list.forEach(System.out::println);
    }
}
